using System.Collections.Generic;
using BCrypt.Net;

namespace FirstTea.Domain.Entities
{
    public class User : EntityBase
    {
    public string? Username { get; set; }
    public string? PasswordHash { get; set; }
    public string? Email { get; set; }
    public string? Phone { get; set; }
    public string? AvatarUrl { get; set; } // 头像路径
    public ICollection<Address>? Addresses { get; set; }
    public ICollection<Order>? Orders { get; set; }
    public ICollection<Cart>? Carts { get; set; }
    public ICollection<Review>? Reviews { get; set; }

        /// <summary>
        /// 设置密码（自动加密）
        /// </summary>
        public void SetPassword(string plainPassword)
        {
            PasswordHash = BCrypt.Net.BCrypt.HashPassword(plainPassword);
        }
        /// <summary>
        /// 校验密码
        /// </summary>
        public bool VerifyPassword(string plainPassword)
        {
            return BCrypt.Net.BCrypt.Verify(plainPassword, PasswordHash ?? "");
        }
    }
}
